//
//  SDSelectPaientViewcontroller.m
//  SKinDiary
//
//  Created by pcyang on 16/7/16.
//  Copyright © 2016年 tencent. All rights reserved.
//

#import "SDSelectPaientViewcontroller.h"
#import "SDPaientEditorViewController.h"
#import "SDNavigationController.h"

@implementation SDSelectPaientViewcontroller
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initSubviews];
    
  //  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAddPaientNotification:) name:kAddNewPaientSuccessNotification object:nil];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear: animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (BOOL)navigationBarHidden
{
    return NO;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (!self.isSearch) {
        NSArray *value = [self.allDataSource objectForKey:self.indexDataSource[indexPath.section]];
        SDPaientInfoItem* userItem = value[indexPath.row];
        self.block(userItem);
    }else{
        self.block(self.searchDataSource[indexPath.row]);
    }
   // [self searchBarCancelButtonClicked:self.searchBar];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)initSubviews
{
    [super initSubviews];
    BOOL naviHidden = [self navigationBarHidden];
    if (!naviHidden && self.navBar != nil)
    {
        [self.navBar setTitle:@"患者"];
        UIImage* backImg = LOAD_IMAGE_USE_CACHE_INBUNDLE(DefaultBundle, @"actionbar_btn_back.png");
        [self.navBar customNaviLeftButton:self action:@selector(onBack:) image:backImg];
        
        UIImage* addImg = LOAD_IMAGE_USE_CACHE_INBUNDLE(DefaultBundle, @"actionbar_btn_add.png");
        [self.navBar customNaviRightButton:self action:@selector(onCreateNewPaient:) image:addImg];
    }
    
    self.friendTableView.height = kScreenHeight - self.navBar.bottom - 44;
}


#pragma mark - ui event
- (void)onBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - ui event
-(void)onCreateNewPaient:(id)sender
{
    SDLoginManager* loginMgr = [SDLoginManager sharedInstance];
    if (![loginMgr isLogin]) {
        [self showLoginViewController];
        return;
    }
    
    SDPaientEditorViewController* editorViewController = [[SDPaientEditorViewController alloc] init];
    
    SDNavigationController* navigationCtrl = [[SDNavigationController alloc] initWithRootViewController:editorViewController];
    [self presentViewController:navigationCtrl animated:YES completion:nil];
}

@end
